<!--  -->
<template>
  <div class='polyIndex-page'>
    <c-title :text="title" :hide="false"></c-title>
    <div class="banner-main">
      <div>
        <swiper style="width: 100%;" :options="swiperOption" ref="mySwiper">
          <swiper-slide v-for="(item, index) in polyInfo.banner" :key="index" class="swiper-itemH">
            <div class="swiper-item " @click="slideNavTo(item.url)">
              <img :src="item.thumb_src"  class="banner"/>
            </div>
          </swiper-slide>
          <!-- <div class="swiper-pagination" slot="pagination"></div> -->
        </swiper>
      </div>
      
      <div class="banner-list flex-a-c">
        <div @click="takeNav">参与记录</div>
        <div v-if="polyInfo.diy_button" @click="diyNav">{{polyInfo.diy_button}}</div>
      </div>
    </div>
    <van-sticky>
      <div class="poly-tab">
        <van-tabs 
          v-model="active" 
          :title-active-color="'var(--themeBaseColor)' || '#FE5E56'" 
          title-inactive-color="#00001C" 
          :color="'var(--themeBaseColor)' || '#FE5E56'"
          line-width="15px"
          :ellipsis="false" 
          @click="categoryTab">
          <block v-for="(item,index) in polyInfo.category" :key="index">
            <van-tab :title="item.category_name" :name="item.id"></van-tab>
          </block>
        </van-tabs>
      </div>
    </van-sticky>
    
    <div class="classify-list" v-if="groupList.length > 0 ">
      <block v-for="(item,index) in groupList" :key="index">
        <div class="classify-item flex-a-c flex-j-sb" @click.stop="groupNav(item.group)">
          <div class="wrap">
            <h3>{{item.group && item.group.group_name}}</h3>
            <p v-if="item.group && item.group.buy_max">每人最高值：{{Number(item.group && item.group.buy_max).toFixed(2) || '0.00'}}</p>
            <div class="flex-a-c classify-time" 
              v-if="computingTime(item.start_time)">
              <span>距离开始</span>
              <van-count-down :time="startDay(item.start_time)">
                <template #default="timeData">
                  <span class="time-sum">{{ timeData.days }}</span>
                  <span class="colon">:</span>
                  <span class="time-sum">{{ timeData.hours }}</span>
                  <span class="colon">:</span>
                  <span class="time-sum">{{ timeData.minutes }}</span>
                  <span class="colon">:</span>
                  <span class="time-sum">{{ timeData.seconds }}</span>
                </template>
              </van-count-down>
            </div>
            <div class="flex-a-c classify-time" v-else>
              <span>距离结束</span>
              <van-count-down :time="beforeDay(item.end_time)" @finish="endDayChange(index)">
                <template #default="timeData">
                  <span class="time-sum">{{ timeData.days }}</span>
                  <span class="colon">:</span>
                  <span class="time-sum">{{ timeData.hours }}</span>
                  <span class="colon">:</span>
                  <span class="time-sum">{{ timeData.minutes }}</span>
                  <span class="colon">:</span>
                  <span class="time-sum">{{ timeData.seconds }}</span>
                </template>
              </van-count-down>
            </div>
            
          </div>
          <div class="classify-btn">
            <div class="btn march" v-if="endTime(item.end_time)">活动结束</div>
            <div class="btn" v-else-if="computingTime(item.start_time)">未开始</div>
            <div class="btn march" v-else>进行中</div>
          </div>
        </div>
      </block>
    </div>
    <van-empty description="暂无数据" v-else/>
    <van-popup v-model="ruleShow"  :style="{ height: '40%',width:'250px',borderRadius:'10px' }" :close-on-click-overlay="false" >
      <div class="rule-flex flex">
        <div class="rule-main flex">
          <h3>{{polyInfo.rule && polyInfo.rule.title}}</h3>
          <div class="rule-content" v-html="polyInfo.rule && polyInfo.rule.desc"></div>
        </div>
        <div class="rule-check flex-a-c">
          <van-checkbox v-model="checked"  shape="square" :checked-color="'var(--themeBaseColor)' || '#E32323'" icon-size="14px"></van-checkbox>
          <p>我已阅读并同意</p>
        </div>
        <div class="rule-confirm" @click="ruleConfirm">确认</div>
      </div>
    </van-popup>
    <div class="m-50"></div>
  </div>
</template>

<script>
import polyIndex_controller from "./polyIndex_controller.js";
export default polyIndex_controller;
</script>
<style lang="scss" scoped>
/* @import url(); 引入公共css类 */
  .rule-main ::v-deep .rule-content img {
    max-width: 100% !important;
    height: auto !important;
    display: block;
    border: 0 !important;
  }
  #appMain.pcStyle .van-popup {
    left: 50%;
  }
  .rule-main ::v-deep .rule-content p {
    text-align: left;
  }
  .m-50 {
    height: 3.125rem;
    clear: both;
  }
  .poly-tab ::v-deep .van-tabs__line {
    bottom:1.3125rem;
  }
  .polyIndex-page {
    .banner-main {
      width:100%;
      margin:0 0 0.75rem 0;
      .banner {
        width:100%;
        max-width: 100%;
        height: auto;
        object-fit: cover;
        display: block;
      }
      .banner-list {
        background-color: #fff;
        
        div {
          font-size: 0.875rem;
          line-height: 0.875rem;
          color: #3B3B4A;
          padding:0.75rem 0;
          flex:0 0 50%;
        }
      }
    }
    .classify-list {
      background-color: #fff;
      .classify-item {
        padding:0.75rem 0;
        margin:0 0.75rem;
        position: relative;
        &::before {
          content: "";
          position: absolute;
          top: -50%;
          bottom: -50%;
          left: -50%;
          right: -50%;
          width: 200%;
          height: 200%;
          -webkit-transform: scale(0.5);
          transform: scale(0.5);
          border-top: solid 0.0625rem #E7E7E7;
          box-sizing:border-box;
        }
        .wrap {
          font-weight: 400;
          text-align: left;
          h3 {
            font-size: 0.875rem;
            color: #333333;
            padding:0 0 0.375rem 0;
            font-weight: 400;
          }
          p {
            color: #AAAAB3;
            padding:0 0 0.375rem 0;
          }
          .classify-time {
            color: #ff2c29;
            font-size: 0.75rem;
            span {
              padding:0 0.25rem 0 0;
            }
            .time-sum {
              padding:0.25rem;
              border-radius: 0.125rem;
              background-color: #FFF0E3;
              font-size: 0.75rem;
              color: #ff2c29;
            }
            .colon {
              font-size: 0.75rem;
              color: #FF9C43;
              padding:0 0.25rem;
            }
          }
        }
        .classify-btn {
          .btn {
            box-sizing: border-box;
            border: 0.0625rem solid var(--themeBaseColor);
            font-size: 0.8125rem;
            line-height: 0.8125rem;
            padding:0.5rem 1.1875rem;
            border-radius: 0.25rem;
            color: var(--themeBaseColor);
          }
          .march {
            background-color: var(--themeBaseColor);
            border:none;
            color:#fff;
          }
        }
      }
    }
    .rule-flex {
      height: 100%;
      justify-content: space-between;
      flex-direction: column;
    }
    .rule-main {
      height: 100%;
      overflow-y:auto ;
      flex-direction: column;
      box-sizing: border-box;
      padding:1.125rem 1.3125rem 0 1.3125rem;
    }
    .rule-check {
      padding:0.375rem 0 0.9375rem 1.3125rem;
      p {
        padding:0 0 0 0.25rem;
        font-size: 0.75rem;
        line-height: 0.75rem;
        color: #3B3B4A;
      }
    }
    .rule-confirm {
      font-size: 0.9375rem;
      line-height: 0.9375rem;
      padding:0.9375rem 0;
      color: var(--themeBaseColor);
      position: relative;
      &::before{
        content: "";
        position: absolute;
        top: -50%;
        bottom: -50%;
        left: -50%;
        right: -50%;
        width: 200%;
        height: 200%;
        -webkit-transform: scale(0.5);
        transform: scale(0.5);
        border-top: solid 0.0625rem #ECECEC;
        box-sizing:border-box;
      }
    }
  }
</style>